package temp3;

import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class ReceiverCountMapper extends Mapper<LongWritable, Text, Text, Text> {
    
    private Text receiver = new Text();
    private final static Text dummy = new Text("1"); // 使用常量值减少对象创建
    private static final int RECEIVER_COLUMN_INDEX = 10; // K列是第11列(0-based索引为10)
    
    @Override
    protected void map(LongWritable key, Text value, Context context) 
            throws IOException, InterruptedException {
        
        // 跳过CSV文件头行（如果有）
        if (key.get() == 0 && value.toString().contains("header")) {
            return;
        }
        
        // 分割CSV行
        String[] columns = value.toString().split(",");
        
        // 确保有足够列且K列不为空
        if (columns.length > RECEIVER_COLUMN_INDEX && !columns[RECEIVER_COLUMN_INDEX].trim().isEmpty()) {
            receiver.set(columns[RECEIVER_COLUMN_INDEX].trim()); // 去除前后空格
            context.write(receiver, dummy);
        }
    }
}